# -*- coding:utf-8 -*-
'''
manage 主要管理程序的启动,以及数据的迁移操作
'''

from flask.ext.migrate import MigrateCommand, Migrate
from flask.ext.script import Manager
from ihome import create_app, redis_store

# # 配置数据库
# app.config['SQLALCHEMY_DATABASE_URI'] = mysql://root:mysql@127.0.0.1/ihome06'
# # 只是为了去除警报,无实际的意义
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

# 通过create_app来获取db和app对象
# from ihome.api_1_0 import api

db, app = create_app()

# 创建Manager对象,托管程序运行
manager = Manager(app)

# 创建迁移对象,需要传入app和db
Migrate(app, db)

# 给命令好添加数据库迁移命令
# 注意: 'db' 不是数据库对象,而是将来终端要使用的命令
# MigrateCommand: 里面存放了init/migrate/upgrade/downgrade/history/current等命令
manager.add_command('db', MigrateCommand)

if __name__ == '__main__':
    # 调用manager.run()方法初始化Manager实例来接收命令行输入
    # Prepares manager to receive command line input.
    # Usually run inside "if __name__ == "__main__" block in a Python script.
    # print app.url_map
    manager.run()
